package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class News extends BaseDomain{

    public static final int STATE_COMMON = 0;//草稿
    public static final int STATE_RELEASE = 1;//发布

    //高级查询中内容归属分类
    public static final Integer TYPE_NEWS = 3;//日报

    private String title;

    private String subtitle;

    private String coverUrl;

    private Integer browseNum=0;//点击浏览量

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date releaseTime;

    private Integer state = STATE_COMMON;//默认是草稿状态

    private Integer sequence;

    private NewsContent newsContent;

    private Integer type = TYPE_NEWS;//默认是日报类型

    public String getStateName()
    {
        String temp = "草稿";
        if(state==STATE_RELEASE)
        {
            temp = "发布";
        }
        return temp;
    }
    public String getJson()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subtitle",subtitle);
        map.put("coverUrl",coverUrl);
        map.put("state",state);

        return JSON.toJSONString(map);
    }

}